<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <!--{include file='comm/header.tpl'}-->
    <title><!--{if $operFlg == 2}-->seo添加<!--{else}-->seo编辑<!--{/if}--></title>
</head>
<body>
<div style="width:100%">

    <div class="items clearfix">
        <h2 style="" class="tal">正在操作：<!--{if $operFlg == 2}-->seo添加<!--{else}-->seo编辑<!--{/if}--></h2>
        <div class="items2">

            <form id="edit_form" onsubmit="return false;">
                <table>
                    <tbody>
                    <tr>
                        <td class="tar" style="width:100px;">页面名称：</td>
                        <td>
                            <input type="text" id="pageName" name="pageName" style="width:300px;ime-mode:active" value="<!--{$seo_obj->pageName}-->" />
                            <font color="red">*</font>
                        </td>
                    </tr>
                    <tr>
                        <td class="tar">页面类型：</td>
                        <td>

                            <!--{if $operFlg == 2}-->
                                <div style="float:left;width: 100px;height: 23px;padding-top:4px;">
                            <!--{else}-->
                                 <div style="float:left;width: 60px;height: 23px;padding-top:8px;">
                            <!--{/if}-->

                                <!--{if $operFlg == 2}-->

                                        <select name="pageType" id="pageType" style="width:100px;">
                                            <option value="">请选择</option>
                                            <option value="1" <!--{if $seo_obj->pageType == 1}--> selected <!--{/if}--> >首页</option>
                                            <option value="2" <!--{if $seo_obj->pageType == 2}--> selected <!--{/if}--> >列表页</option>
                                            <option value="3" <!--{if $seo_obj->pageType == 3}--> selected <!--{/if}--> >详情页</option>
                                        </select>

                                <!--{else}-->

                                    <!--{if $seo_obj->pageType == 1}-->
                                        <font style="font-size: 14px;">首页</font>
                                    <!--{elseif $seo_obj->pageType == 2}-->
                                        <font style="font-size: 14px;padding-right: 10px;">列表页</font>
                                    <!--{elseif $seo_obj->pageType == 3}-->
                                        <font style="font-size: 14px;">详情页</font>
                                    <!--{/if}-->
                                    <input type="hidden" name="pageType" id="pageType" value="<!--{$seo_obj->pageType}-->">

                                <!--{/if}-->

                            </div>

                            <div id="goodsDiv" <!--{if $operFlg == 3 && $seo_obj->pageType == 2}--> style="float: left;margin-left: 20px;" <!--{else}--> style="float: left;margin-left: 20px;display: none;" <!--{/if}--> >
                                <!--{$categoryTpl}-->
                            </div>
							
							<div <!--{if $operFlg == 2}--> style="float: left;" <!--{else}--> style="display:none;" <!--{/if}--> ><font color="red">*</font></div>
							
							<div id="goodsProCode" <!--{if $operFlg == 3 && $seo_obj->pageType == 3}-->style="float: left;margin-left: 20px;" <!--{else}--> style="float: left;margin-left: 20px;display: none;" <!--{/if}-->>
								商品编号：
								<input type="text" id="product_code" name="product_code" value="<!--{if $seo_obj->uid != 0}--><!--{$seo_obj->uid}--><!--{/if}-->" />
								<span id="goodsName"></span>
							</div>
                            
                        </td>
                    </tr>
                    <tr>
                        <td class="tar">标题：</td>
                        <td>
                            <textarea name="title" id="title" style="width: 96%;height: 60px;margin-bottom: 10px;margin-top: 5px;"><!--{$seo_obj->title}--></textarea>
                        </td>
                    </tr>
                    <tr>
                        <td class="tar">关键字：</td>
                        <td>
                            <textarea name="keywords" id="keywords" style="width: 96%;height:90px;margin-bottom: 10px;"><!--{$seo_obj->keywords}--></textarea>
                        </td>
                    </tr>
                    <tr>
                        <td class="tar">描述：</td>
                        <td>
                            <textarea name="description" id="description" style="width: 96%;height:90px;"><!--{$seo_obj->description}--></textarea>
                        </td>
                    </tr>
                    <tr>
                        <td class="tar">使用状态：</td>
                        <td >
                            <input type="radio" name="useFlg" value="1" <!--{if $operFlg == 2 || $seo_obj->useFlg == 1}-->checked="checked"<!--{/if}-->>启用
                            <input type="radio" name="useFlg" value="0" <!--{if $operFlg == 3 && $seo_obj->useFlg == 0}-->checked="checked"<!--{/if}-->>禁用
                        </td>
                    </tr>
                    <input type="hidden" name="uid" value="<!--{$seo_obj->uid}-->">
                    <input type="hidden" name="pageType" value="<!--{$seo_obj->pageType}-->">
                    </tbody>
                </table>
            </form>

        </div>
    </div>

    <div class="bottom_fixbox">
        <div class="rectbox tac">
            <input type="button" class="btn" onclick="seo.check();" value="<!--{if $operFlg == 2}-->seo添加<!--{else}-->seo编辑<!--{/if}-->" />&nbsp;&nbsp;&nbsp;
            <input type="button" class="btn" onclick="E.closeWindows();" value="关闭" />
        </div>
    </div>



</div>

<script type="text/javascript">

    $(document).ready(function(){
        <!--{if $operFlg == 3}-->
        $("#bigCate").val('<!--{$seo_obj->bigCategoryID}-->')
        changeBigCate();
        $("#midCate").val("<!--{$seo_obj->midCategoryID}-->") ;
        changeMidCate();
        $("#smallCate").val("<!--{$seo_obj->smallCategoryID}-->");
        <!--{/if}-->
    });

	$("#product_code").keypress(function (e){
        if(e.keyCode == '13'){
			var product_code = $('#product_code').val();
			$.ajax({
                type: "POST",
                url: "/invokingAjax-backend/system/seo.ajax?operFlg=6",
                dataType: "JSON",
                data:{'product_code': product_code},
                success: function(result_obj){
                    if (result_obj.code == 200) {
                       	$('#goodsName').html(result_obj.message);
                    } else {
                        E.alert(result_obj.message);
                    }
                }
            });
        }
    });
	
    //添加或编辑的标志
    var operFlg = '<!--{$operFlg}-->';

    $("#pageType").change(function(){

        var value = $(this).val();

        if( value == '2' ){

            $("#goodsDiv").show();
			$('#goodsProCode').hide();

        }else if(value == '3'){
			$("#goodsDiv").hide();
			$('#goodsProCode').show();
		}else{

            $("#goodsDiv").hide();
			$('#goodsProCode').hide();
            if( value != '' ){
                jquery_ajax(5,{pageType:value},seo.callback);
            }

        }

    })

    var seo = {

        dt: "",

        check: function() {

            this.dt = E.getFormValues('edit_form');
            var pageType = $("#pageType").val();
            var bigcategory = $("#bigCate").val();

            var error_msg = "";

            if ( this.dt.pageName == "")
                error_msg += "页面名称不能为空<br />";

            if (  pageType == "")
                error_msg += "请选择页面类型<br />";

            if(  pageType == 2 && bigcategory == 0 )
                error_msg += "请选择大分类<br />";

            if (error_msg != "")
                E.alert(error_msg);
            else {
                this.dt = E.concat( this.dt , {pageType:pageType} );
                this.add();
            }

        },

        add: function() {
            $.ajax({
                type: "POST",
                url: "/invokingAjax-backend/system/seo.ajax?operFlg=2",
                dataType: "JSON",
                data: this.dt,
                success: function( result_obj ) {
                    if (result_obj.code == 200) {

                        E.opener("seolist.load");

                        if( operFlg == 2 ){
                            E.alert(result_obj.message, 2 , "E.refresh");
                        }else{
                            E.alert(result_obj.message, 2 , "E.closeWindows");
                        }


                    } else {
                        E.alert(result_obj.message);
                    }
                }
            });
        },

        //回调函数
        callback:function( obj ){

            if( obj.code != 200 )
                E.alert(obj.message);

        }

    };

    function jquery_ajax(flg,data,func){
        $.ajax({
            type: "post",
            url: "/invokingAjax-backend/system/seo.ajax?operFlg=" + flg,
            dataType: "json",
            data: data,
            success: function( result_obj ) {
                func(result_obj);
            },
            error : function(msg){
                alert('网络不给力，请重新尝试...');
            }
        });
    }


</script>

</body>

</html>
